package com.woniu.smart.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.smart.dto.WarningDTO;
import com.woniu.smart.entity.Fault;
import com.woniu.smart.entity.Warning;
import com.woniu.smart.service.FaultService;
import com.woniu.smart.service.WarningService;
import com.woniu.smart.util.Result;
import com.woniu.smart.vo.WarningVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: smart
 * @description:
 * @author: qqq
 * @create: 2022-10-22 15:14
 **/
@RestController
@RequestMapping("warnings")
public class WarningController {
    @Autowired
    private WarningService warningService;
    @Autowired
    private FaultService faultService;
    @PostMapping("queryAll")
    public Result queryAll(@RequestBody WarningDTO warningDTO){
        List<WarningVO> warningVOList = warningService.selectAll(warningDTO);
        PageInfo<WarningVO> warningVOPageInfo =new PageInfo<>(warningVOList);
        return Result.ok().data("warningList",warningVOPageInfo);
    }
    @GetMapping("{id}")
    public Result queryById(@PathVariable("id") Long id){
        WarningVO warning = warningService.selectByPrimaryKey(id);
        return Result.ok().data("warning",warning);
    }
    @GetMapping("faults")
    public Result queryFault(){
        List<Fault> faults = faultService.selectAll();
        return Result.ok().data("faults",faults);
    }
    @PostMapping()
    public Result add(@RequestBody Warning warning){
        int i = warningService.insertSelective(warning);
        return Result.ok();
    }
    @PostMapping("task")
    public Result task(@RequestBody WarningVO warning){
        int i = warningService.requestDesignating(warning);
        return Result.ok();
    }
    @PutMapping()
    public Result update(@RequestBody WarningVO warning){
        int i = warningService.updateByPrimaryKeySelective(warning);
        return Result.ok();
    }
    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Long id){
        int i = warningService.deleteByPrimaryKey(id);
        return Result.ok();
    }
}
